package com.songshuai.customer.client.service.impl;

import com.songshuai.customer.client.dao.customer.InvitationRecordMapper;
import com.songshuai.customer.client.dto.request.InvitationRecord.AddInvitationRecordReqDto;
import com.songshuai.customer.client.model.InvitationRecord;
import com.songshuai.customer.client.service.InvitationRecordService;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.exception.BusinessException;
import com.songshuai.webapi.baseapi.utils.PropertiesUtil;
import com.songshuai.webapi.baseapi.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author:wbl
 * @Date: 2019/3/27
 */
@Service
public class InvitationRecordServiceImpl implements InvitationRecordService {

    @Autowired
    private SnowFlakeUtil snowFlakeUtil;

    @Autowired
    private InvitationRecordMapper invitationRecordMapper;

    @Override
    public void addInvitationRecord(String customId,AddInvitationRecordReqDto parm) {
        try {
            InvitationRecord invitationRecord = new InvitationRecord();
            PropertiesUtil.copyProperties(parm, invitationRecord);
            invitationRecord.setId(snowFlakeUtil.nextId());
            invitationRecord.setCreateBy(customId);
            invitationRecord.setCreateTime(new Date());
            invitationRecord.setInviter(customId);
            invitationRecord.setChannel("cust");
            invitationRecordMapper.addInvitationRecord(invitationRecord);
        }catch (Exception e) {
            throw new BusinessException(ResultStatus.ERROR_CREATE_FAILED.getErrorMsg(), ResultStatus.FAILOfficial);
        }
    }
}
